package sourceagile.server.utilities;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;


public class CreateTempFile {

	public static File get(String classContent, String filePath) {

		String fileName = FileNameGenerator.getFileName(filePath);

		File file = getTempFile(classContent, fileName);

		return file;
	}

	private static File getTempFile(String classContent, String fileName) {

		File tempFile = null;

		try {

			tempFile = File.createTempFile(fileName, ".java");

			OutputStream out = new FileOutputStream(tempFile);
			out.write(classContent.getBytes());
			out.close();

		} catch (IOException e) {

			e.printStackTrace();
		}

		return tempFile;
	}

}
